package com.nf.health.app.adapter;

import android.app.Activity;
import android.text.TextUtils;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.nf.health.app.R;
import com.nf.health.app.customview.SwipeView;
import com.nf.health.app.models.DoctorCommnetVo;
import com.nf.health.app.utils.ImageLoaderUtils;

import java.util.ArrayList;
import java.util.List;

/*
*
* 医生评论适配器
*/

public class DoctorCommentAdapter extends BaseAdapter {

	private String type;
	protected static final String TAG = DoctorCommentAdapter.class.getSimpleName();
	private Activity context;
	private List<DoctorCommnetVo> doctors;
	public ArrayList<SwipeView> unClosedSwipeView = new ArrayList<SwipeView>();

	public DoctorCommentAdapter(Activity context, List<DoctorCommnetVo> doctors,String type) {
		this.context = context;
		this.doctors = doctors;
		this.type = type;
	}
	public void setDoctorCommentnotifyDataChanged(List<DoctorCommnetVo> doctors) {
		this.doctors = doctors;
		notifyDataSetChanged();
	}

	@Override
	public int getCount() {
		if(type.equals("y")){
			return 0;
		}else if (doctors != null) {
			return doctors.size();
		}else{
			return 10;
		}
	}

	@Override
	public Object getItem(int position) {
		return null;
	}

	@Override
	public long getItemId(int position) {
		return 0;
	}

	@Override
	public View getView(final int position, View convertView, ViewGroup parent) {
		ViewHolder holder = ViewHolder.get(parent, convertView, R.layout.item_doctor_comment, position);
		ImageView iv_user_head_icon = holder.getView(R.id.iv_user_head_icon);
		ImageLoaderUtils.getinstance(context).getImage(iv_user_head_icon, doctors.get(position).getHimg(), R.drawable.default_head);
		TextView tv_unread_msg = holder.getView(R.id.tv_unread_msg);
		holder.setText(R.id.health_eciality_details,doctors.get(position).getMessage());//内容
		holder.setText(R.id.doctor_name, doctors.get(position).getNick());//名称
		if(TextUtils.isEmpty(doctors.get(position).getPosttime())){

		}else{
			String time[] =  doctors.get(position).getPosttime().split(" ");
			holder.setText(R.id.doctor_time,time[0]); //回复最后一句话
		}

		if(TextUtils.isEmpty(doctors.get(position).getScore())){

		}else{

			if(doctors.get(position).getScore().equals("4")) {
				holder.setText(R.id.doctor_form,"非常满意");//来自
			}else if(doctors.get(position).getScore().equals("3")) {
				holder.setText(R.id.doctor_form,"基本满意");//来自

			}else if(doctors.get(position).getScore().equals("2")){
				holder.setText(R.id.doctor_form,"不满意");//来自

			}else if(doctors.get(position).getScore().equals("1")){
				holder.setText(R.id.doctor_form,"失望");//来自
			}else{
				holder.setText(R.id.doctor_form,"非常满意");
			}
		}
		return holder.getConvertView();
	}
}